package com.chaihu.generator.backend;

import com.chaihu.generator.util.FileUtilBase;

public class GeneratorSaveIn extends BaseGenerator {

    /**
     * 生成代码
     * @param data
     */
    public void generator(Data data) throws Exception {
        StringBuffer sb = readFile("backendTemplate/SaveIn.txt");
        String fileContext = sb.toString();
        fileContext = fileContext
                .replace("@@moduleName@@",data.getModuleName())
                .replace("MenuGroup",toUpperCaseFirstOne(data.getName()))
                .replace("menugroup",data.getName().toLowerCase())
                .replace("描述",data.getDesc());

        String writePath = BaseGenerator.getClassPath()
                + "out/backend/in/Save"+toUpperCaseFirstOne(data.getName())+"In.java";
        writeFile(writePath, fileContext);
        //复制生成的文件到对应分区目录下
        if (data.isAutoMove()) {
            String distPath = "chaihu-bean\\src\\main\\java\\com\\chaihu\\bean\\in\\" + data.getModuleName() + "\\" + data.getName().toLowerCase() + "\\" + "Save" + toUpperCaseFirstOne(data.getName()) + "In.java";
//            System.out.println(distPath);
            FileUtilBase.copyfile(writePath, distPath);
        }
    }
}
